﻿using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HarmonyLib;
using System.Windows.Forms;
using UnityEngine;
using Hearthstone;

namespace bald.bot
{

	class Program
	{
		public static void Main(string[] args)
		{
            //new Task(delegate
            //{
            //    System.Windows.Forms.Application.EnableVisualStyles();
            //    System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            //    System.Windows.Forms.Application.Run(new Form1());
            //}).Start();
            try
			{
				new Harmony("Assembly-CSharp.dll").PatchAll(Assembly.GetExecutingAssembly());
				smethod_3("Harmony:Load Success", bool_0: false);
			}
			catch (ThreadAbortException)
			{
				return;
			}
			catch (Exception ex2)
			{
				smethod_3("ex:" + string.Format("Exception e{0} message{1} stacktrace{2}", ex2, ex2.Message, ex2.StackTrace), bool_0: false);
			}
			/*
			ShouldRefreshStatus = true;
			GClass0.speedratio = 1f;
			smethod_3("GClass0.speedratio" + GClass0.speedratio);
			new Task(delegate
			{
				//smethod_1();
			}).Start();*/



			smethod_3("end main");
		}
		//static public bool ShouldRefreshStatus = false;

		/*
		[HarmonyPatch(typeof(iTweenManager), "Add", new Type[]
		{
			typeof(iTween)
		})]
		private class MyPatch3
		{
			// Token: 0x06000026 RID: 38
			[HarmonyPrefix]
			public static void Prefix()
			{
				smethod_3("MyPatch3 Prefix", false, "0");
				try
				{
					HearthstoneApplication cv = HearthstoneApplication.Get();
					Type t = cv.GetType();
					FieldInfo field = t.GetField("s_mode",     //要访问的私有变量名 myValue
					BindingFlags.NonPublic | BindingFlags.Instance);
					field.SetValue(cv, ApplicationMode.INTERNAL);
					if (ShouldRefreshStatus)
					{
						GClass0.smethod_0();
						ShouldRefreshStatus = false;
					}
				}
				catch (ThreadAbortException)
				{
				}
				catch (Exception ex)
				{
					smethod_3("MyPatch3" + string.Format("Exception e{0} message{1} stacktrace{2}", ex, ex.Message, ex.StackTrace), false);
				}
			}
		}
		*/
		[HarmonyPatch(typeof(GraphicsResolution), "IsAspectRatioWithinLimit", new Type[]
		{
			typeof(int),
			typeof(int),
			typeof(bool)
		})]
		private class MyPatch1
		{
			// Token: 0x06000026 RID: 38
			[HarmonyPrefix]
			public static bool Prefix(ref bool __result,int width, int height, bool isWindowedMode)
			{
				smethod_3("MyPatch1 Prefix", false, "0");
				try
				{
					__result = true;
				}
				catch (Exception ex)
				{
					smethod_3("MyPatch1" + string.Format("Exception e{0} message{1} stacktrace{2}", ex, ex.Message, ex.StackTrace), false);
				}
				return false;
			}
		}
		//static public class GClass0
		//{
		//	static PropertyInfo propertyInfo_0;
		//	static public float speedratio;
		//	public static void smethod_0()
		//	{
		//		smethod_3("smethod_0", false, "0");
		//		//Class15.FuncClassFunc0();
		//		//propertyInfo_0 = (Assembly.Load("UnityEngine.CoreModule.dll").GetType("UnityEngine.Time")).GetProperty("timeScale");
		//		//propertyInfo_0.SetValue(null, speedratio, null);
		//		Time.timeScale = speedratio;
				
		//		//HearthstoneApplication.s_mode = ApplicationMode.INTERNAL;
		//	}
		//}

		/// <summary>
		/// 日志信息
		/// </summary>
		/// <param name="string_0"></param>
		/// <param name="bool_0"></param>
		/// <param name="string_1"></param>
		static void smethod_3(string string_0, bool bool_0 = false, string string_1 = "0")
		{
			return;
			StreamWriter streamWriter = new StreamWriter("C:\\1\\buding.txt", true, Encoding.Default);
			streamWriter.WriteLine(string.Concat(new string[]
			{
				DateTime.Now.ToString("HH:mm:ss.fff"),
				" ",
				string_0,
				" s_1:",
				string_1
			}));
			streamWriter.Flush();
			streamWriter.Close();
		}
	}
}



